﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data.SQLite;

namespace HW9
{
    public partial class Form1 : Form
    {
        // 连接字符串
        public string connString;
        // 连接
        public SQLiteConnection conn;
        // 适配器
        public SQLiteDataAdapter adapter;
        // 指令构造器
        public SQLiteCommandBuilder cb;
        // 数据集
        public DataSet ds;
        public int current_row = 0;
        public int num_of_row;
        public Form1()
        {
            connString = "Data Source = csharphw9.db";
            SQLiteConnection conn = new SQLiteConnection(connString);
            conn.Open();
            InitializeComponent();
            string sql = "SELECT * FROM wordslist;";
            adapter = new SQLiteDataAdapter(sql, conn);
            cb = new SQLiteCommandBuilder(adapter);
            ds = new DataSet();
            adapter.Fill(ds, "wordslist");
            num_of_row = ds.Tables[0].Rows.Count;
            eng.Text = ds.Tables[0].Rows[current_row].ItemArray[1].ToString();
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "wordslist";
        }

        private void next_pressed_Click(object sender, EventArgs e)
        {
            current_row = (current_row + 1) % num_of_row;
            eng.Text = ds.Tables[0].Rows[current_row].ItemArray[1].ToString();
            this.rightornot.Text = "";
            this.right_ans.Text = "";
        }

        private void check_pressed_Click(object sender, EventArgs e)
        {
            string rs = ds.Tables[0].Rows[current_row].ItemArray[2].ToString();
            if (this.chnInput.Text == rs)
            {
                this.rightornot.Text = "答对了！";
            }
            else
            {
                this.rightornot.Text = "答错了...";
            }
            this.right_ans.Text = rs;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            adapter.Update(ds, "wordslist");
            num_of_row = ds.Tables[0].Rows.Count;
        }
    }
}
